//
//  WallListCell.m
//  HotWord
//
//  Created by 贺 欢 on 13-3-18.
//
//

#import "WallListCell.h"
#import "ITTImageView.h"
#import "QuestionAnswer.h"

@interface WallListCell ()
@property (retain, nonatomic) IBOutlet ITTImageView *userHeaderImageView;
@property (retain, nonatomic) IBOutlet UILabel *nickNameLabel;
@property (retain, nonatomic) IBOutlet UILabel *titleLabel;
@property (retain, nonatomic) IBOutlet UILabel *questionLabel;
@property (retain, nonatomic) IBOutlet UILabel *answerLabel;
@property (retain, nonatomic) IBOutlet UILabel *answerCountLabel;
@property (retain, nonatomic) IBOutlet UILabel *answerLabelLabel;
@property (retain, nonatomic) IBOutlet UILabel *timeLabel;


@end

@implementation WallListCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setDataSourceWithQuestion:(Question *)question
{
    [_userHeaderImageView setDefaultImage:[UIImage imageNamed:@"photo_card_small.png"]];
    if ([@"1" isEqualToString:question.isAnonymous])
    {
        _nickNameLabel.text = @"匿名用户";
    }
    else
    {
        [_userHeaderImageView loadImage: question.avater];
        _nickNameLabel.text = question.nickName;
    }
    _titleLabel.text = question.title;
    
    NSTimeInterval time = [question.timestamp doubleValue];
    if (time > 0)
    {
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:time];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy年M月d日 HH:mm"];
        NSString *dateString = [dateFormatter stringFromDate:date];
        [dateFormatter release];
        _timeLabel.text = dateString;

        
    }
    else
    {
        _timeLabel.text = @"";
    }
    
    _questionLabel.text = [NSString stringWithFormat:@"问：%@",question.content];
    if ([question.answers count] > 0)
    {
        QuestionAnswer *answer = [question.answers objectAtIndex:0];
        _answerLabel.text = [NSString stringWithFormat:@"答：%@",answer.content];
    }
    else
    {
       _answerLabel.text = @"暂无回答";
    }
    
    _answerCountLabel.text = [NSString stringWithFormat:@"%d回复",[question.answers count]];
    if (IS_STRING_NOT_EMPTY(question.tag.name))
    {
        _answerLabelLabel.text = [NSString stringWithFormat:@"标签：%@ · %@",question.examTag, question.tag.name,nil];
    }
    else
    {
        _answerLabelLabel.text = [NSString stringWithFormat:@"标签：%@",question.examTag];
    }
}

- (void)dealloc
{
    [_userHeaderImageView release];
    [_nickNameLabel release];
    [_titleLabel release];
    [_questionLabel release];
    [_answerLabel release];
    [_answerCountLabel release];
    [_answerLabelLabel release];
    [_timeLabel release];
    [super dealloc];
}

@end
